using System.Collections.Generic;
using Voodoo.Sauce.Internal.SDKs;

namespace Voodoo.Sauce.Debugger
{
	public class SDKListDebugScreen : Screen
	{
		private void Start()
		{
			InstantiateSdkList(VoodooSauceSDKs.Load().SDKs);
		}

		private void InstantiateSdkList(SDKList sdkList)
		{
			OpenFoldout("Info");
			RowLabel("VS Version", sdkList.vsVersion);
			RowLabel("Last Update Date", sdkList.lastUpdateDate);
			CloseFoldout();
			foreach (MediationSDK ad in sdkList.ads)
			{
				OpenFoldout(ad.name);
				CreateMediation(ad);
				CloseFoldout();
			}
			OpenFoldout("Analytics");
			RowLabel("SDK name", new string[3] { "Unity", "iOS", "Android" });
			CreateSdk(sdkList.analytics);
			CloseFoldout();
			OpenFoldout("Crashlytics");
			RowLabel("SDK name", new string[3] { "Unity", "iOS", "Android" });
			CreateSdk(sdkList.crashlytics);
			CloseFoldout();
			OpenFoldout("AudioAds");
			RowLabel("SDK name", new string[3] { "Unity", "iOS", "Android" });
			CreateSdk(sdkList.audioAds);
			CloseFoldout();
			OpenFoldout("CMP");
			RowLabel("SDK name", new string[3] { "Unity", "iOS", "Android" });
			CreateSdk(sdkList.consentManagementProvider);
			CloseFoldout();
		}

		private void CreateMediation(MediationSDK mediation)
		{
			RowLabel(mediation.name, mediation.GetVersionsAsArray());
			RowLabel("Ad Network", new string[4] { "iOS", "Adapter", "Android", "Adapter" });
			foreach (AdNetworkSDK adNetwork in mediation.adNetworks)
			{
				CreateAdNetwork(adNetwork);
			}
			if (mediation.otherUtilitySdk == null || mediation.otherUtilitySdk.Count <= 0)
			{
				return;
			}
			RowLabel("Other Utility SDK", new string[3] { "Unity", "iOS", "Android" });
			foreach (SDK item in mediation.otherUtilitySdk)
			{
				CreateMediationOtherUtilitySdk(item);
			}
		}

		private void CreateMediationOtherUtilitySdk(SDK otherUtilitySdk)
		{
			RowLabel(otherUtilitySdk.name, otherUtilitySdk.GetVersionsAsArray());
		}

		private void CreateAdNetwork(AdNetworkSDK adNetwork)
		{
			string text = "";
			if (adNetwork.ios.certified || adNetwork.android.certified)
			{
				text = " (c)";
			}
			RowLabel(adNetwork.name + text, adNetwork.GetVersionsAsArray());
		}

		private void CreateSdk(List<SDK> sdks)
		{
			foreach (SDK sdk in sdks)
			{
				RowLabel(sdk.name, sdk.versions.GetVersionsAsArray());
			}
		}
	}
}
